`
https://leetcode.cn/problems/find-the-longest-semi-repetitive-substring/
`

/**
 * @param {string} s
 * @return {number}
 */
var longestSemiRepetitiveSubstring = function (s) {
  const n = s.length
  let res = 1
  let same = 0
  let left = 1, right = 1

  while (right < n) {
    same += s[right] === s[right - 1]
    right++

    while (same > 1) {
      same -= s[left] === s[left - 1]
      left++
    }

    res = Math.max(res, right - left + 1)
  }

  return res
};